package com.szeldon.declatest;

import java.io.IOException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

import org.testng.annotations.BeforeSuite;

import com.szeldon.utils.ValuesUtils;

/**
 * Class configuring TestNG test suite for Declatest.
 * 
 * @author szeldon
 * 
 */
public class DeclatestTestsConfigurator {

    @BeforeSuite
    public void beforeTestSuite() throws SecurityException, IOException {
        String fileSeparator = System.getProperty("file.separator");

        Calendar calendar = new GregorianCalendar();
        String year = "" + calendar.get(Calendar.YEAR);
        String month = ValuesUtils.convertToTwoDigitString(calendar.get(Calendar.MONTH) + 1);
        String day = ValuesUtils.convertToTwoDigitString(calendar.get(Calendar.DAY_OF_MONTH));
        String hour = ValuesUtils.convertToTwoDigitString(calendar.get(Calendar.HOUR_OF_DAY));
        String minute = ValuesUtils.convertToTwoDigitString(calendar.get(Calendar.MINUTE));
        String second = ValuesUtils.convertToTwoDigitString(calendar.get(Calendar.SECOND));

        Handler fileHandler = new FileHandler("logs" + fileSeparator + "test-" + year + month + day + "-" + hour + ""
                + minute + "" + second + ".log");
        fileHandler.setFormatter(new SimpleFormatter());
        Logger.getLogger("").addHandler(fileHandler);
        Logger.getLogger("com.szeldon.declatest").setLevel(Level.FINEST);

    }

}
